/*
3
    1    2    3
    1    3    2
    2    1    3
    2    3    1
    3    1    2
    3    2    1
*/
#include<bits/stdc++.h>
using namespace std;

int n,a[20];
bool book[20]; 
void shuchu(){
	for(int i=1;i<=n;i++)
		printf("%5d",a[i]);
		cout<<endl;
} 
    
void dfs(int x){
	if(x>n){
	    shuchu();
	    return ;
	}
	
	for(int i=1;i<=n;i++){
		if(!book[i]){
			a[x]=i;
			book[i]=1;
			dfs(x+1);
			book[i]=0;
		}
	}
}

int main(){
	cin>>n;
	dfs(1);
	
	return 0;
}